import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);
const user_info = {
	username:'',
	mobile:'',
	avatar:'',
	is_certification:'',
	referrer:''
}
const store = new Vuex.Store({
    state: {
		index:uni.getStorageSync('index') || '',
		token:uni.getStorageSync('token') || '',
		userinfo:uni.getStorageSync('userinfo')?JSON.parse(uni.getStorageSync('userinfo')) : user_info,
    },
    mutations: {
		SET_INDEX(state,val){
			state.index = val
			uni.setStorageSync('index', val)
		},
		SET_TOKEN(state,val){
			state.token = val
			uni.setStorageSync('token', val)
		},
		SET_INFO(state,info){
			state.userinfo = info?JSON.parse(info):''
			uni.setStorageSync('userinfo', info)
		},
    },
	actions: {
		GetUserInfo({commit}) {
			return Vue.prototype.$httpApi.userIndex().then(res => {
				commit('SET_INFO', JSON.stringify(res.data))
			})
		},
	},
	modules: {
		
	},
});
export default store;